

import 'package:baby/UI/Widgets/HtmlContent/TransformPipeline.dart';
import 'package:baby/UI/Widgets/HtmlContent/TransformUnit.dart';
import 'package:flutter_test/flutter_test.dart';

class ProcessorUnitA extends TransformUnit<Map<String, dynamic>, Object> {
  @override
  void execution(context, data) {
    if (data is String && data == "p")
      pipeLineContext.processWith("Text");
  }
}

class ProcessorUnitB extends TransformUnit<Map<String, dynamic>, Object> {
  @override
  void execution(context, data) {
    if (data is String && data == "img")
      pipeLineContext.processWith("CachedNetworkImage");
  }
}

class ProcessorUnitC extends TransformUnit<Map<String, dynamic>, Object> {
  @override
  void execution(context, data) {
    if (data is List<String>){
      var widgets = <String>[];

      data.forEach((item){
        var result = pipeLineContext.process(item);
        if (result is String) widgets.add(result);
      });

      pipeLineContext.processWith("Column(children: ${widgets.join(",")})");
    }
  }
}

void main(){
  test("main test", (){
    var feature = {
      "name": "yeganaaa",
      "age": 21
    };

    var pipeLine = TransformPipeLine<Map<String, dynamic>, Object>(featureContext: feature);
    pipeLine.installPipe(ProcessorUnitA());
    pipeLine.installPipe(ProcessorUnitB());
    pipeLine.installPipe(ProcessorUnitC());

    var result = pipeLine.start(["p", "img", "p"]);
    print(result);
  });
}
